// VObjectManager.h
//
#ifndef VOBJECTMANAGER_H
#define VOBJECTMANAGER_H

#include "OpenGL/Math.h"
#include "OpenGL/Box.h"

#include <map>
#include <vector>
#include <list>


namespace OpenGL {
	class Renderer;
}

class VObject;
class SelectionSet;

class VObjectManager
{
	typedef std::map<unsigned int ,VObject*>  Objects;
	typedef std::list<VObject*>				  ObjectList;
	typedef std::map<unsigned int, ObjectList>  ObjectIndex;	// map from object types to 

private:
	OpenGL::Renderer *_renderer; // not owned
	VObject          *_hilightedObject;	
	SelectionSet     *_selectionSet;

	Objects     vObjects;
	ObjectIndex vObjectIndex;

	OpenGL::Math::dvec3 _pickPoint;
	void VObjectManager::drawForSelection();
	void createIndex( VObject *obj );
	void removeIndex( VObject *obj );
public:
	explicit VObjectManager( OpenGL::Renderer *r );
	~VObjectManager();

	bool addObject( VObject *o );

	VObject *getObject( unsigned int id );
	VObject *getHilightedObject() const;

	//void hilightObjectAt( int x, int y );
	void hilightObject( VObject *obj );
	void hilightObjectAt( const OpenGL::Math::dvec3 &p );
	void selectObjectAt( const OpenGL::Math::dvec3 &p );
	//bool selectObjectAt( int x, int y );
	//bool selectArea( int xmin, int ymin, int xmax, int ymax );
	void selectArea( const OpenGL::Math::dvec3 &p0, const OpenGL::Math::dvec3 &p1 );

	std::vector<unsigned int> getSelectedObjects()const;

	VObject *removeObject( unsigned int id );
	void destroyAllObjects();

	void updateObjects();
	OpenGL::Math::box3 boundingBox() const;

	void drawObjects();
};

#endif